package com.infra.micro.oss.controller;

import com.infra.common.resp.PageEx;
import com.infra.micro.oss.domain.service.FileInfoService;
import com.infra.micro.oss.model.req.QueryFileInfoReq;
import com.infra.micro.oss.model.vo.FileInfoVO;
import com.infra.common.resp.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件服务
 *
 * @author PD
 */
@RequestMapping("/api/oss")
@RestController
@Api(tags = {"原始文件查询服务"})
public class FileInfoController {
    @Resource
    private FileInfoService fileInfoService;

    @ApiImplicitParam(name = "fileId", value = "系统文件ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @ApiOperation(value = "根据原始文件ID查询文件", notes = "根据原始文件ID查询文件信息", produces = "application/json")
    @GetMapping("/fileInfo/{fileId}")
    public Response<FileInfoVO> queryByFileId(@PathVariable("fileId") Long fileId) {
        return fileInfoService.queryByFileId(fileId);
    }

    @ApiImplicitParam(name = "fileIds", value = "系统文件ID列表", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @ApiOperation(value = "根据原始文件ID集合查询文件", notes = "根据原始文件ID集合查询文件信息", produces = "application/json")
    @PostMapping("/fileInfos")
    public Response<List<FileInfoVO>> queryByFileIds(@RequestBody List<Long> fileIds) {
        return fileInfoService.queryByFileIds(fileIds);
    }

    @ApiOperation(value = "根据条件分页查询原始文件列表", notes = "根据条件分页查询原始文件列表", produces = "application/json")
    @GetMapping(value = "/fileInfo/list")
    public Response<PageEx<FileInfoVO, QueryFileInfoReq>> queryByPage(QueryFileInfoReq req) {
        return fileInfoService.queryByPage(req);
    }
}
